package pl.edu.agh.broker.mns.client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;

import pl.edu.agh.broker.mns.shared.MultiNameService;


public class MultiNameServiceLocator {

	public static MultiNameService getMultiNameService(String urlRef)
			throws MalformedURLException, IOException, ClassNotFoundException {
		ObjectInputStream ois = new ObjectInputStream(
				new URL(urlRef).openStream());
		MultiNameService ret = (MultiNameService) ois.readObject();
		ois.close();
		return ret;
	}

	public static MultiNameService getMultiNameService(String ip, int port)
			throws UnknownHostException, IOException, ClassNotFoundException {
		Socket socket = new Socket(ip, port);
		ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
		MultiNameService ret = (MultiNameService) ois.readObject();
		ois.close();
		return ret;
	}
}
